//
//  InviteCell.swift
//  WalkNovel
//
//  Created by Kevin on 2023/12/20.
//

import UIKit

class InviteRewardsCell: UITableViewCell {
    
    lazy var bgView: UIView = {
        let view = UIView()
        view.backgroundColor = .white
        view.wn_cornerWithBorder(4)
        return view
    }()
    
    lazy var numLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 16)
        label.textColor = .init(named: "red_FE6390")
        return label
    }()
    
    lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 14)
        label.numberOfLines = 0
        label.textColor = .black
        return label
    }()
    
    lazy var rewardsImage: UIImageView = {
        return UIImageView()
    }()

    let strArr = ["Send your special invite link to a friend.", "Your friend downloads WalkNovel via the link.", "Both the inviter and invitee will get rewards."]
    let imageArr = ["invite_reward_share", "invite_reward_shop", "book_gift"]

    var rewardsType = 0 {
        didSet {
            numLabel.text = "\(rewardsType+1)"
            nameLabel.text = strArr[rewardsType]
            rewardsImage.image = UIImage(named: imageArr[rewardsType])
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        backgroundColor = .clear
        contentView.addSubview(bgView)
        bgView.addSubview(numLabel)
        bgView.addSubview(rewardsImage)
        bgView.addSubview(nameLabel)
        bgView.snp.makeConstraints { (make) in
            make.top.equalTo(0)
            make.left.equalTo(12)
            make.bottom.equalTo(-12)
            make.right.equalTo(-12)
        }
        numLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(12)
        }
        rewardsImage.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalTo(-6)
            make.width.height.equalTo(36)
        }
        nameLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(30)
            make.right.equalTo(rewardsImage.snp.left).offset(-12)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

class InviteTaskCell: UITableViewCell {
    
    lazy var bgView: UIView = {
        let view = UIView()
        view.backgroundColor = .white
        view.wn_cornerWithBorder(4)
        return view
    }()
    
    lazy var taskImage: UIImageView = {
        return UIImageView()
    }()
    
    lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 14)
        label.numberOfLines = 0
        label.textColor = .init(named: "black_333333")
        return label
    }()
    
    lazy var inviterLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .regular, size: 12)
        label.textColor = .init(named: "gray_999999")
        return label
    }()
    
    lazy var inviteeLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .regular, size: 12)
        label.textColor = .init(named: "gray_999999")
        return label
    }()
    
    let strArr = ["Download the app and check in on the same day", "Unlock and read 1 chapter in 3 days after downloading the app", "Top up in 3 days after downloading the app"]
    let imageArr = ["login_logo", "task_lock", "setting_recharge_gold"]
    let countArr = [30, 20, 20]
    var taskType = 0 {
        didSet {
            taskImage.image = UIImage(named: imageArr[taskType])
            nameLabel.text = strArr[taskType]
            inviterLabel.text = "For inviter: \(countArr[taskType]) Golds"
            inviteeLabel.text = "For invitee: \(countArr[taskType]) Golds"
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        backgroundColor = .clear
        contentView.addSubview(bgView)
        bgView.addSubview(taskImage)
        bgView.addSubview(nameLabel)
        bgView.addSubview(inviterLabel)
        bgView.addSubview(inviteeLabel)
        bgView.snp.makeConstraints { (make) in
            make.top.equalTo(0)
            make.left.equalTo(12)
            make.bottom.equalTo(-12)
            make.right.equalTo(-12)
        }
        taskImage.snp.makeConstraints { (make) in
            make.top.equalTo(12)
            make.left.equalTo(12)
            make.width.height.equalTo(36)
        }
        nameLabel.snp.makeConstraints { (make) in
            make.top.equalTo(12)
            make.left.equalTo(taskImage.snp.right).offset(8)
            make.right.equalTo(-20)
        }
        inviterLabel.snp.makeConstraints { (make) in
            make.top.equalTo(nameLabel.snp.bottom).offset(6)
            make.left.equalTo(nameLabel.snp.left)
        }
        inviteeLabel.snp.makeConstraints { (make) in
            make.top.equalTo(inviterLabel.snp.bottom).offset(6)
            make.left.equalTo(nameLabel.snp.left)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
